package com.yanmaohu.yulia.statement;

import com.yanmaohu.yulia.bean.SqlExecutableStatementList;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Bright Lee
 */
public final class TriggeredSqlStatement {

    private int beginIndex;
    private int endIndex;
    private boolean beginAtomicEnd;
    private SqlExecutableStatementList sqlProcedureStatementList;

    public TriggeredSqlStatement(int beginIndex,
                                 int endIndex,
                                 SqlExecutableStatementList sqlProcedureStatementList) {
        this.beginIndex = beginIndex;
        this.endIndex = endIndex;
        this.beginAtomicEnd = true;
        this.sqlProcedureStatementList = sqlProcedureStatementList;
    }

    public TriggeredSqlStatement(SqlExecutableStatement sqlProcedureStatement) {
        this.beginIndex = sqlProcedureStatement.getBeginIndex();
        this.endIndex = sqlProcedureStatement.getEndIndex();
        this.beginAtomicEnd = false;
        List<SqlExecutableStatement> sqlProcedureStatementList = new ArrayList<>(1);
        sqlProcedureStatementList.add(sqlProcedureStatement);
        this.sqlProcedureStatementList = new SqlExecutableStatementList(sqlProcedureStatementList);
    }

    public int getBeginIndex() {
        return beginIndex;
    }

    public int getEndIndex() {
        return endIndex;
    }

    public boolean isBeginAtomicEnd() {
        return beginAtomicEnd;
    }

    public SqlExecutableStatementList getSqlProcedureStatementList() {
        return sqlProcedureStatementList;
    }

    public SqlExecutableStatement getSqlExecutableStatement() {
        return sqlProcedureStatementList.get(0);
    }

}
